/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.annotations.CascadeOnDelete;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "PendingSO")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PendingSO.findAll", query = "SELECT p FROM PendingSO p"),
    @NamedQuery(name = "PendingSO.findByPsoid", query = "SELECT p FROM PendingSO p WHERE p.psoid = :psoid"),
    @NamedQuery(name = "PendingSO.findByPSOAllocationID", query = "SELECT p FROM PendingSO p WHERE p.pSOAllocationID = :pSOAllocationID"),
    @NamedQuery(name = "PendingSO.findByPSODate", query = "SELECT p FROM PendingSO p WHERE p.pSODate = :pSODate"),
    @NamedQuery(name = "PendingSO.findByPSOComplete", query = "SELECT p FROM PendingSO p WHERE p.pSOComplete = ?1"),
    @NamedQuery(name = "PendingSO.findOpenPSOs", query = "SELECT p FROM PendingSO p WHERE p.pSOComplete = false")})
public class PendingSO implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "PSOID")
    private Integer psoid;
    @Basic(optional = false)
    @NotNull
    @Column(name = "PSOAllocationID")
    private int pSOAllocationID;
    @Basic(optional = false)
    @NotNull
    @Column(name = "PSODate")
    @Temporal(TemporalType.DATE)
    private Date pSODate;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 0, max = 65535)
    @Column(name = "PSOXML")
    private String psoxml;
    @Basic(optional = false)
    @NotNull
    @Column(name = "version")
    @Version
    private int version;
    @Basic(optional = false)
    @NotNull
    @Column(name = "PSOComplete")
    private boolean pSOComplete;
    @JoinColumn(name = "PSOCustID", referencedColumnName = "CId")
    @ManyToOne(optional = false)
    private Customer cust;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTPSO",
        joinColumns={ @JoinColumn(name="PSOID", referencedColumnName="PSOID")},
        inverseJoinColumns={ @JoinColumn(name="psolID", referencedColumnName="psoID", unique=true)}
    )
    private List<PSOLines> psoLinesCollection;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTIPSO",
        joinColumns={ @JoinColumn(name="PSOID", referencedColumnName="PSOID")},
        inverseJoinColumns={ @JoinColumn(name="ipsoID", referencedColumnName="ipsoID", unique=true)}
    )
    private List<InvPSOLines> invPSOLinesCollection;

    public PendingSO() {
    }

    public PendingSO(Integer psoid) {
        this.psoid = psoid;
    }

    public PendingSO(Integer psoid, int pSOAllocationID, Date pSODate, String psoxml, boolean pSOComplete, int version) {
        this.psoid = psoid;
        this.pSOAllocationID = pSOAllocationID;
        this.pSODate = pSODate;
        this.psoxml = psoxml;
        this.pSOComplete = pSOComplete;
        this.version = version;
    }

    public Integer getPsoid() {
        return psoid;
    }

    public void setPsoid(Integer psoid) {
        this.psoid = psoid;
    }

    public int getPSOAllocationID() {
        return pSOAllocationID;
    }

    public void setPSOAllocationID(int pSOAllocationID) {
        this.pSOAllocationID = pSOAllocationID;
    }

    public Date getPSODate() {
        return pSODate;
    }

    public void setPSODate(Date pSODate) {
        this.pSODate = pSODate;
    }

    public String getPsoxml() {
        return psoxml;
    }

    public void setPsoxml(String psoxml) {
        this.psoxml = psoxml;
    }

    public boolean getPSOComplete() {
        return pSOComplete;
    }

    public void setPSOComplete(boolean pSOComplete) {
        this.pSOComplete = pSOComplete;
    }

    public Customer getPSOCustID() {
        return cust;
    }

    public void setPSOCustID(Customer cust) {
        this.cust = cust;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public List<PSOLines> getPSOLinesCollection() {
        return psoLinesCollection;
    }

    public void setPSOLinesCollection(List<PSOLines> psoLinesCollection) {
        this.psoLinesCollection = psoLinesCollection;
    }

    public List<InvPSOLines> getInvPSOLinesCollection() {
        return invPSOLinesCollection;
    }

    public void setInvPSOLinesCollection(List<InvPSOLines> invPSOLinesCollection) {
        this.invPSOLinesCollection = invPSOLinesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (psoid != null ? psoid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PendingSO)) {
            return false;
        }
        PendingSO other = (PendingSO) object;
        if ((this.psoid == null && other.psoid != null) || (this.psoid != null && !this.psoid.equals(other.psoid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.PendingSO[ psoid=" + psoid + " ]";
    }
    
}
